 var util = require("../../utils/util.js"),
   api = require("../../utils/api.js"),
   app = getApp();
 Page({
   data: {
     pageIndex: 1,
     pageSize: 10,
     list: [],
     showEmpty: false,
     proScroll: false,
     keyword:''
   },
   onLoad(option) {
     api.default.toLogin().then(res => {
       this.init();
     })
   },
   async init() {
     let param = {
       page: this.data.pageIndex,
       pageSize: this.data.pageSize,
       title:this.data.keyword
     }
     let {
       data: {
         list,
         total
       }
     } = await api.default.serveList(param);
     let listArr = Array.isArray(list) ? list : [];
     listArr.forEach(item=>{
       item.proceedingendtime_text=util.getUnixToDate(item.proceedingendtime)
     })
     this.setData({
       proScroll: listArr.length < this.data.pageSize ? true : false,
       list: this.data.pageIndex == 1 ? listArr : [...this.data.list, ...listArr],
       showEmpty: total == 0 ? true : false,
     })
     wx.stopPullDownRefresh();
     wx.hideNavigationBarLoading();
   },

   goToDetail(e) { 
    let id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '/pages/home/caselistDetail/caselistDetail?id=' + id,
    })
  },
   /**
    * 页面上拉触底事件的处理函数
    */
   onReachBottom() {
     if (!this.data.proScroll) {
       let page = this.data.pageIndex;
       page = page + 1;
       this.setData({
         pageIndex: page
       })
       this.init();
     }
   },
   onShareAppMessage(e) {
    return util.shareEvent(e)
  },
  onPullDownRefresh(){
    wx.showNavigationBarLoading();
    this.setData({
      pageIndex: 1
    })
    this.init();
  },
  onChange(e){
    this.setData({keyword:e.detail})
  },
  onSearch(){
    this.setData({pageIndex:1});
    this.init();
  },
  onClear(){
    this.setData({pageIndex:1,keyword:''});
    this.init();
  }
 })